//#include "UnityPrefix.h"
#include "Rect.h"

using namespace std;

Rectf::Rectf ()
{
  Reset();
}
void Rectf::SetCenterPos (float _x, float _y)
{
	x = _x - width * 0.5f;
	y = _y - height * 0.5f;
}

Vector2f Rectf::GetCenterPos()const
{
	return Vector2f(x + width * 0.5f, y + height * 0.5f);
}

void Rectf::Clamp (const Rectf &r) {
	float x2 = x + width;
	float y2 = y + height;
	float rx2 = r.x + r.width;
	float ry2 = r.y + r.height;

	if (x < r.x) x = r.x;
	if (x2 > rx2) x2 = rx2;
	if (y < r.y) y = r.y;
	if (y2 > ry2) y2 = ry2;

	width = x2 - x;
	if (width < 0.0f) width = 0.0f;

	height = y2 - y;
	if (height < 0.0f) height = 0.0f;
}
